import os
import threading
import time
import requests
from bs4 import BeautifulSoup


DIR_IMG = './static/img/'
DIR_JSON = './static/json/'
DIR_VIDEO = './static/video/'

# 创建目录
if not os.path.exists(DIR_IMG):
    os.mkdir(DIR_IMG)
if not os.path.exists(DIR_JSON):
    os.mkdir(DIR_JSON)
if not os.path.exists(DIR_VIDEO):
    os.mkdir(DIR_VIDEO)


# 链接项目
class UrlItem:
    def __init__(self, title, href):
        self.title = title
        self.href = href


class Crawler(threading.Thread):
    def __init__(self):
        super().__init__()
        self.title = ''
        self.tab = ''
        self.this = ''
        self.start()

    def run(self):
        print(self.__class__)
        pass

    # 获取电影列表
    def getMovies(self, result):
        return result

    # 获取附件地址
    def getAttach(self, result):
        return result


# 是否为空
def isEmpty(obj): return obj is None or len(obj) == 0


# 是否非空
def isNotEmpty(obj): return ~isEmpty(obj)


# 获取HTML
def getHtml(url):
    return requests.get(url)


# 获取解析器
def getHtmlSoup(url):
    return BeautifulSoup(getHtml(url).text, 'html.parser')


# 获取物理路径
def getUrlPath(path, url):
    return path + url.split('/')[-1]
